package com.zb_study.udp;

import java.io.IOException;
import java.net.*;

public class UDPSenderB {
    public static void main(String[] args) throws IOException {


        DatagramSocket socket = new DatagramSocket(9998);
        byte[] data = "hello, 明天去玩~".getBytes();

        DatagramPacket packet =
                new DatagramPacket(data, data.length, InetAddress.getByName("192.168.137.1"), 9999);

        socket.send(packet);




        byte[] buf = new byte[1024];
         packet = new DatagramPacket(buf, buf.length);

        //System.out.println("接收端A 等待接收数据....");
        socket.receive(packet);

        int length = packet.getLength();
        data = packet.getData();
        String s = new String(data, 0, length);
        System.out.println(s);

        socket.close();
        System.out.println("B端退出");
    }
}
